void loop(){    
    if(rewrite_all){
        Tft.fillRectangle(0,0,239,319, barvy[0]);
    }
    
    //uvodni obrazovka
    if(stat == 0){
        if(rewrite_all){
            Tft.fillRectangle(10,10,220,145, barvy[2]);
            Tft.fillRectangle(10,165,220,145, barvy[2]);      
            Tft.drawString("LOAD", 35, 55, 7, BLACK);
            Tft.drawString("NEW", 55, 210, 7, BLACK);  
       		rewrite_all = false;
        }     
                         
        checkP();
        
        if(p.z > 10){
            //tlacitko LOAD
            if(p.y < 160){
                rewrite_all = true;
                rewrite_game = true;   
				if(!SD.exists("G2048.TXT")){
                    stat = 0; 
                    Tft.fillRectangle(20,95,200,100, barvy[17]);
                    Tft.drawString("ERROR", 28, 123, 6, BLACK); 
					
					delay(500);
                }
                else{
                    stat = 1;
                    soubor = SD.open("G2048.TXT");
                    int i = 0;
                    byte p;
                    
                    for(int i=0; i < 4; i++){ //vycistime plochu
                        for(int j = 0; j < 4; j++){
                            plocha[i][j] = 0;
                        }
                    }
                    
                    while(soubor.available()){
                        p = soubor.read();
                        plocha[(i - i%4) /4][i % 4] = p;
                        i++;               
                    }
                    soubor.close();
                }
            }
            
            //tlacitko NEW
            else if(p.y >= 160){
                rewrite_all = true;
                rewrite_game = true;
                moved = false;
                added = 0;
                gEnd = false;
                gWin = false;
                stat = 1; //pokracovat budeme hrou
                
				//cela plocha se nastavi na 0
                for(int i = 0; i < 4; i++){
                    for(int j = 0; j < 4; j++){
                        plocha[i][j] = 0;
                    }
                }
                
                addTile();
                addTile();
            }
        }
    }